package com.hmall.search.listenner;

import com.hmall.common.constants.MqConstants;
import com.hmall.search.service.ISearchService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class itemUpAndDownListenner {
    @Autowired
    private ISearchService searchService;
    @RabbitListener(bindings=@QueueBinding(
            value=@Queue(name= MqConstants.ITEM_UP_QUEUQ,durable="true"),
            exchange = @Exchange(name=MqConstants.ITEM_EXCHANGE_NAME,type= ExchangeTypes.TOPIC),
            key = MqConstants.ITEM_UP_KEY
    ))
    public void itemUp(Long id){
        System.out.println("itemUp:"+id);
        searchService.saveItem( id);
    }
    @RabbitListener(bindings=@QueueBinding(
            value=@Queue(name= MqConstants.ITEM_DOWN_QUEUQ,durable="true"),
            exchange = @Exchange(name=MqConstants.ITEM_EXCHANGE_NAME,type= ExchangeTypes.TOPIC),
            key = MqConstants.ITEM_DOWN_KEY
    ))
    public void itemDown(Long id){
        System.out.println("itemDown:"+id);
        searchService.deleteItem( id);
    }
}
